﻿using System;
using System.Text;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using Microsoft.ApplicationBlocks.Data;
//using FunkeLab;

namespace AnyOffice.general
{
    public partial class menu : BasePage 
    {
        private StringBuilder builder;
        protected void Page_Load(object sender, EventArgs e)
        {
         
            if (!this.Page.IsPostBack && (Request.QueryString["menu_id"] != null))
            {
                string str = Request.QueryString["menu_id"].ToString();
                UserCache cache = new UserCache();
                string funcIdStr = cache.FuncIdStr;
                string commandText = "SELECT * FROM [dbo].[Sys_Menu] WHERE [MenuId] = " + Request.QueryString["menu_id"].ToString();
                DataTable table = SqlHelper.ExecuteDataset(ConfigManager.ConnectionString, CommandType.Text, commandText).Tables[0];
                if (table.Rows.Count > 0)
                {
                  //  this.litMenuName.Text = table.Rows[0]["MenuName"].ToString();
                   // this.litImage.Text = table.Rows[0]["Image"].ToString();
                }
               
                builder = new StringBuilder();
                builder.Append("<table width='100%' height='100%' border='0' cellspacing='0' cellpadding='0' class='outFullLine'>");
               
                string str4 = "SELECT * FROM [dbo].[Sys_Function] WHERE CHARINDEX(','+ CAST([FuncId] as nvarchar(20)) + ',','," + funcIdStr + ",')>0 and len(MenuId)=4 and left(MenuId,2)='" + str + "' ORDER BY MenuId ASC";
                DataTable table2 = SqlHelper.ExecuteDataset(ConfigManager.ConnectionString, CommandType.Text, str4).Tables[0];
                #  region if
                if (table2.Rows.Count > 0)
                {                
                    for (int i = 0; i < table2.Rows.Count; i++)
                    {                     
                        if (table2.Rows[i]["FuncCode"].ToString().IndexOf("@") < 0)//没有子菜单
                        {

                            builder.Append(string.Format("<tr><td class='btnSubModule' id='menuTitleBox{0}' onclick=\"OpenCloseSubMenu({1});menuJump('{2}');\" title='{3}'><div id='menuTitle{4}'>{5}</div></td></tr>",
                                i, i, table2.Rows[i]["FuncCode"].ToString() + "/index.aspx",table2.Rows[i]["FuncName"].ToString(),i, table2.Rows[i]["FuncName"].ToString()));
                           
                        }
                        else//有子菜单
                        {
                            builder.Append(string.Format("<tr id='statusType{0}'><td class='btnSubModule' onClick=\"OpenCloseSubMenu({1})\" id='menuTitleBox{2}'><div id='menuTitle{3}'>",
                                i, i, i , i ));
                            builder.Append("<table width='100%' cellpadding='0' cellspacing='0' border='0'><tr>");
                            builder.Append(string.Format("<td nowrap title='{0}'>{1}</td> <td align='right' width='16'><span class='btnSubMenuOpen'>&nbsp;</span></td>",
                                table2.Rows[i]["FuncName"], table2.Rows[i]["FuncName"]));
                            builder.Append("</tr></table>");
                            builder.Append("</div> </td> </tr>");
                           
                        }
                        string str5 = "SELECT * FROM [dbo].[Sys_Function] WHERE (CHARINDEX(','+ CAST(FuncId as nvarchar(20)) + ',','," + funcIdStr + ",')>0) AND (len(MenuID)=6) AND (left(MenuID,4) ='" + table2.Rows[i]["MenuID"].ToString() + "') ORDER BY MenuId ASC";
                        DataTable table3 = SqlHelper.ExecuteDataset(ConfigManager.ConnectionString, CommandType.Text, str5).Tables[0];
                        if (table3.Rows.Count > 0)
                        {
                            builder.Append(string.Format("<tr id='submenuBox{0}' valign='top' style='display:none;'><td height='{1}' class='btnSubModuleBox'>", i, 20 * table3.Rows.Count));
                            for (int j = 0; j < table3.Rows.Count; j++)
                            {
      
                                builder.Append(string.Format("<div style='height:20px'><img src='/images/square_blueS.gif' align='absMiddle'> <a href='{0}' target='main'>{1}</a><br /></div>",
                                     table3.Rows[j]["FuncCode"].ToString() + "/index.aspx", table3.Rows[j]["FuncName"]));

                            }
                              builder.Append("</td></tr>");

                        }                      
                       
                    }
                }
                #endregion
                builder.Append("<tr><td>&nbsp;</td></tr></table>");  
            }
            this.litMenu.Text = builder.ToString();
        }
    }
}
